﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Escape
{
    class Basic
    {
        static Screen currentScreen;

        public static Random random = new Random();
        public static SpriteFont font;
        public static SpriteFont littleFont;
        public static SpriteBatch spriteBatch;
        public static ContentManager content;
        public static GameTime time;
        public static GraphicsDevice device;
        public static GraphicsDeviceManager dManager;

        public static Texture2D basicTex;

        public static int width, height;
        public static Rectangle screenBounds;

        public static Rectangle mousePos;

        static SamplerState ss;

        public static void SetUp(GraphicsDeviceManager deviceM, ContentManager Content)
        {
            dManager = deviceM;
            device = deviceM.GraphicsDevice;
            content = Content;
            spriteBatch = new SpriteBatch(device);
            time = new GameTime();

            font = Content.Load<SpriteFont>("SpriteFont1");
            littleFont = Content.Load<SpriteFont>("SpriteFont2");
            basicTex = Content.Load<Texture2D>("Textures\\Unbenannt");

            width = dManager.PreferredBackBufferWidth;
            height = dManager.PreferredBackBufferHeight;

            screenBounds = new Rectangle(0, 0, width, height);

            SetScreen(new TitleScreen());

            if (currentScreen != null)
                currentScreen.Init();

            ss = new SamplerState();
            ss.Filter = TextureFilter.Point;
        }

        public static void Update()
        {

            mousePos = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);

            if (currentScreen != null)
                currentScreen.Update();
        }

        public static void Render()
        {

            device.SamplerStates[0] = ss;

            spriteBatch.Begin();

            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState = BlendState.AlphaBlend;


            if (currentScreen != null)
                currentScreen.Render();
            spriteBatch.End();
        }

        public static void SetScreen(Screen screen)
        {
            if (currentScreen != null)
                currentScreen.Quit();
            currentScreen = screen;
            currentScreen.Init();
        }
    }
}
